<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ include file="../common/header.jsp"%>

<style>
    .kv-item label {width: 7em;}
    .kv-item input[type=number],input[type=email]{
        width: 250px;
        height: 28px;
        border: 1px solid #c5c5c5;
        border-right-color: #e0e0e0;
        border-bottom-color: #e0e0e0;
        outline: none;
        padding: 0 10px;
    }
</style>

<div id="saper-container">
    <div id="saper-hd"></div>
    <div id="saper-bd">
        <div class="subfiled clearfix">
            <h2>${titleName}</h2>
        </div>
        <div class="subfiled-content">
            <form class="saper-form">
                <div class="layui-row">
                    <div class="layui-col-md6 layui-col-xs12">
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>所在省市：</label>
                            <div class="kv-item-content">
                                <input type="text" value="四川省宜宾市" readonly/>
                            </div>
                            <div class="kv-item-tip">默认</div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>
                                <span class="impInfo">*</span>所在县：</label>
                            <div class="kv-item-content">
                                <input type="text" value="兴文县" readonly/>
                            </div>
                            <div class="kv-item-tip">默认</div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>
                                <span class="impInfo">*</span>所在乡镇：</label>
                            <div class="kv-item-content">
                                <select name="townId" onchange="select_change(this)" value-type="integer">
                                    <c:forEach items="${townList}" var="town">
                                        <option value="${town.townId}">${town.townName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>
                                <span class="impInfo">*</span>所在村庄：</label>
                            <div class="kv-item-content">
                                <select name="villageId" value-type="integer">
                                    <c:forEach items="${villageList}" var="village">
                                        <option value="${village.villageId}">${village.villageName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>姓名：</label>
                            <div class="kv-item-content">
                                <input name="name" type="text" placeholder="请输入真实姓名" autocomplete="off" required/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>身份证号：</label>
                            <div class="kv-item-content">
                                <input name="idCard" type="text" placeholder="请输入身份证号" autocomplete="off" required/>
                            </div>
                            <div class="kv-item-tip">确保真实有效</div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>手机号：</label>
                            <div class="kv-item-content">
                                <input name="tellphone" type="text" placeholder="请输入手机号" autocomplete="off" required/>
                            </div>
                            <div class="kv-item-tip">确保真实有效</div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>性别：</label>
                            <div class="kv-item-content">
                                <select name="sex" value-type="integer">
                                    <option value="0">男</option>
                                    <option value="1">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>年龄：</label>
                            <div class="kv-item-content">
                                <input name="age" type="number" placeholder="请输入年龄" maxlength="3" required value-type="integer"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>民族：</label>
                            <div class="kv-item-content">
                                <select name="nation" value-type="integer">
                                    <option value="1">汉族</option>
                                    <option value="2">苗族</option>
                                    <option value="3">彝族</option>
                                    <option value="4">其他</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>是否劳动力：</label>
                            <div class="kv-item-content">
                                <select name="isLdl" value-type="integer">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>是否残疾：</label>
                            <div class="kv-item-content">
                                <select name="isCj" value-type="integer">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>健康状态：</label>
                            <div class="kv-item-content">
                                <select name="healthStatus" value-type="integer">
                                    <option value="1">健康</option>
                                    <option value="2">长期慢性病</option>
                                    <option value="3">患大病</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>是否低保：</label>
                            <div class="kv-item-content">
                                <select name="isDb" value-type="integer">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>是否保险：</label>
                            <div class="kv-item-content">
                                <select name="isBx" value-type="integer">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>是否五保：</label>
                            <div class="kv-item-content">
                                <select name="isWb" value-type="integer">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-xs12">
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>就业状况：</label>
                            <div class="kv-item-content">
                                <input name="work" type="text" placeholder="请输入就业情况，不得超过50字" maxlength="50" autocomplete="off" required/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>工作行业：</label>
                            <div class="kv-item-content">
                                <input name="industry" type="text" placeholder="请输入工作行业" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>政治面貌：</label>
                            <div class="kv-item-content">
                                <select name="political_outlook">
                                    <option value="党员">党员</option>
                                    <option value="预备党员">预备党员</option>
                                    <option value="团员">团员</option>
                                    <option value="群众">群众</option>
                                    <option value="其他">其他</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>婚姻状况：</label>
                            <div class="kv-item-content">
                                <select name="marriage" value-type="string">
                                    <option value="已婚">已婚</option>
                                    <option value="未婚">未婚</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>户口性质：</label>
                            <div class="kv-item-content">
                                <select name="nohRegister" value-type="string">
                                    <option value="城市">城市</option>
                                    <option value="农村">农村</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>户籍所在地：</label>
                            <div class="kv-item-content">
                                <input name="hrResiter" type="text" placeholder="请输入户籍所在地" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>教育程度：</label>
                            <div class="kv-item-content">
                                <select name="education" value-type="string">
                                    <option value="中专及以下">中专及以下</option>
                                    <option value="大专">大专</option>
                                    <option value="本科">本科</option>
                                    <option value="研究生及以上">研究生及以上</option>
                                </select>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>收入情况：</label>
                            <div class="kv-item-content">
                                <input name="income" type="number" placeholder="请输入收入情况" autocomplete="off" required value-type="integer"/>
                            </div>
                            <div class="kv-item-tip">单位：元</div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>出生年月：</label>
                            <div class="kv-item-content">
                                <input name="born" type="text" placeholder="请输入年月日" readonly  autocomplete="off" required id="bornTime"/>
                            </div>
                            <div class="kv-item-tip">例如：1999-01-09</div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>出生地：</label>
                            <div class="kv-item-content">
                                <input name="bornAddress" type="text" placeholder="请输入出生地" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>毕业学校：</label>
                            <div class="kv-item-content">
                                <input name="school" type="text" placeholder="请输入毕业学校" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>所学专业：</label>
                            <div class="kv-item-content">
                                <input name="major" type="text" placeholder="请输入所学专业" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>email：</label>
                            <div class="kv-item-content">
                                <input name="email" type="email" placeholder="请输入email" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>qq：</label>
                            <div class="kv-item-content">
                                <input name="qq" type="number" placeholder="请输入qq号" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>微信：</label>
                            <div class="kv-item-content">
                                <input name="weixin" type="text" placeholder="请输入微信号" autocomplete="off"/>
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label>家庭住址：</label>
                            <div class="kv-item-content">
                                <input name="livein" type="text" placeholder="请输入家庭住址" autocomplete="off"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="buttons">
                    <a href="javascript:;" class="sapar-btn sapar-btn-recom">确定</a>
                </div>
            </form>
        </div>
    </div>
    <div id="saper-ft"></div>
</div>

<%@ include file="../common/footer.jsp"%>
<script type="text/javascript">

    <%--下拉框更新--%>
    function select_change(obj) {
        var that = $(obj);
        var select = that[0];
        var select_name = $(select).attr("name");
        if (select_name === "townId")
            $.post("/ajax/grid/getVillage", {
                townId: $(select).val()
            }, function (res) {
                if (res.code === 1) {
                    var data = res.data, len = res.data.length;
                    if (len === 0) {
                        $("select[name=villageId]").html("");
                        $("select[name=villageId]").next().html("没有可以选取的类别");
                    } else {
                        var str = '';
                        for (var i = 0; i < len; i++) {
                            var d = data[i];
                            str += '<option value="' + d['villageId'] + '">' + d['villageName'] + '</option>\n'
                        }
                        $("select[name=villageId]").html(str);
                        $("select[name=villageId]").next().html(data[0]['villageName']);
                    }
                } else
                    console.log("请求失败！");
            });
    }

    <%--初始化时间选择器--%>
    laydate.render({
        elem: '#bornTime' //指定元素
    });

    <%--表单提交--%>
    $(".buttons .sapar-btn-recom").click(function(){
        var inputs = $("input"),param = {};
        for(var i=0,len=inputs.length;i<len;i++){
            var inp = inputs[i];
            var key = $(inp).attr("name");
            if(key !== undefined){
                var re = $(inp).attr("required");
                var va = $(inp).val();
                if(re !== undefined && va === ""){
                    layer.msg("红*标记的内容必须要填写！");
                    $(inp).focus();
                    return false;
                }

                var vt = $(inp).attr("value-type");
                if(vt !== undefined && vt === "integer") va = parseInt(va);
                param[key] = va;
            }
        }
        var selects = $("select");
        for(var i=0,len=selects.length;i<len;i++){
            var sel = selects[i];
            var key = $(sel).attr("name");
            if(key !== undefined){
                var va = $(sel).val();
                var vt = $(sel).attr("value-type");
                if(vt !== undefined && vt === "integer") va = parseInt(va);
                param[key] = va;
            }
        }

        console.log(JSON.stringify(param));
        $.post("/ajax/grid/savePoor",{param:JSON.stringify(param)},function(res){
            if(res.code === 1)
                layer.msg("增加成功！",{},function(){refresh()});
        });
    });

</script>
